// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require(CONFIG.BasePath + "js/enterprise/base");
	var router = require("../hash/pageRouter");
	var constant = require("constant");
	var css_pickup = require("./accountEvaluate.css");
	var css_raty = require(CONFIG.BasePath + "js/jQuery-raty/css/jquery.raty.css");
	var financeId;
	var tools = require("tools");

	var init = function(page) {
		financeId = page.params.financeId;
		router.init();
		initEvent();
	};

	var initEvent = function() {
		$('.financeRaty').raty({
			path: function() {
				return CONFIG.BasePath + "js/jQuery-raty/img/";
			},
			score: function() {
				return 5;
			}
		});
		if (base.getData("sid") == null) {
			location.href = "../login/login.html";
		}

		//点击项目基本详情financeDetail
		$(".financeDetail").unbind("click").click(function() {
			router.route("account/accountDetail.html?financeId=" + financeId, true);

		});
		$("#evaluteSubmit").unbind("click").click(function() {
			if ($.trim($(".financeContent").val()) == "" || $(".financeContent").val() == null) {
				$(".error_info").css("visibility", "visible");
				$(".error_info").html("请输入评论信息！");
			} else {
				$(".error_info").css("visibility", "hidden");
				tools.protectDoubleClick();
				createFinanceEvaluate();
			}
		});
	};

	//新增评价
	var createFinanceEvaluate = function() {
		var loanSpeed = $(".loanSpeed input").val();
		var cargoSecurity = $(".cargoSecurity input").val();
		var deliverySpeed = $(".deliverySpeed input").val();
		var serviceQuality = $(".serviceQuality input").val();
		var financeContent = $(".financeContent").val();
		if (financeContent.length <= 256) {
			base.fnAjax({
				action: "createFinanceEvaluate.json",
				async: false,
				oData: {
					financeId: financeId,
					loanSpeed: loanSpeed,
					cargoSecurity: cargoSecurity,
					deliverySpeed: deliverySpeed,
					serviceQuality: serviceQuality,
					content: financeContent
				}, //传递参数
				fnSuccess: function(data) {
					tools.cancelProtectDoubleClick();
					if (data.status == 200) {
						router.route("account/accountDetail.html?financeId=" + financeId);
					} else {
						//                  base.alert(2,"信息获取失败");
					}
				}
			});
		}else{
			base.alert(2, "评价内容不能超过255个字符！");
		}
	};

	return {
		init: init
	};
});